Skip to content

Conversation

johncowie
Copy link
Contributor

@johncowie johncowie commented Oct 10, 2025

Extends #141 with the following:

  • The default value for private_subnets_offset is set to 128, so there's a decent gap between the public and private subnet cidrs. This means that if a new availability zone is added to the list, the existing private subnets won't need to get destroyed to make way for the new public subset.
  • Also supports explicitly specifying the public and private subnet cidrs with the availabilty zones, in which case these will be favoured instead of the calculated ones. If users are adding a new AZ this will allow them to ensure that the subnets of previously created AZs will be preserved.

@johncowie johncowie changed the title Support az updates experimental Adding support for updating Availability Zones v2 Oct 10, 2025
@johncowie johncowie marked this pull request as ready for review October 13, 2025 14:57
@johncowie johncowie changed the title Adding support for updating Availability Zones v2 Adding support for updating Availability Zones (v2) Oct 13, 2025
_validate_az_input = (
(var.availability_zones == null && var.availability_zone_configurations == null) ||
(var.availability_zones != null && var.availability_zone_configurations != null)
) ? tobool("ERROR: Exactly one of availability_zones or availability_zone_configurations must be specified.") : true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this works but it feels weird. I did a search and there's custom validation you can do on input variables. Would that work here? Something like:

variable "availability_zones" {
  type    = list(string)
  default = null
  
  validation {
    condition = (
      (var.availability_zones == null) != 
      (var.availability_zone_configurations == null)
    )
    error_message = "Exactly one of availability_zones or availability_zone_configurations must be specified."
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I tried this first, but I don't think you can reference another variable in a variable definition. I'll double-check this though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aye, disnae work.

Screenshot 2025-10-14 at 11 29 00

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other option is combining the types into the var.availability_zones var. Unfortunately terraform doesn't support type unions, so I think to do this you'd make the type of var.availability_zones an any and then add validation to check that it's either a list of strings or a list of objects. But then you lose the typing and resulting type hints, which seemed a shame to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or given it's already somewhat of a breaking change, could lean harder into that by just supporting the new list-of-objects type, with the subnet CIDRs being optional.

```


* The default value for the `private_subnets_offset` variable has been changed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that if users upgrade, their subnets will change? Or is this accounted for in the move blocks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it does if they relied on the default value of private_subnets_offset before. They can avoid this by setting private_subnets_offset to 0 explicitly, albeit they'll still need to do the move blocks to avoid stuff being destroyed. I'll add some additional documentation to this effect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants